package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.ITagLibraryService;
import com.tarena.lbs.basic.web.service.IUserTagsService;
import com.tarena.lbs.common.basic.converter.TagLibraryConverter;
import com.tarena.lbs.pojo.basic.bo.TagLibraryBO;
import com.tarena.lbs.pojo.basic.param.TagLibraryParam;
import com.tarena.lbs.pojo.basic.param.UserTagsParam;
import com.tarena.lbs.pojo.basic.query.TagLibraryQuery;
import com.tarena.lbs.pojo.basic.vo.TagLibraryVO;
import com.tarena.lbs.pojo.basic.vo.UserItemTag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
//@RequestMapping("/admin/basic/tagLibrary/info")
@Slf4j
@Api(tags = "标签管理")
public class TagLibraryController {

    @Resource
    private ITagLibraryService tagLibraryService;

    @Resource
    private IUserTagsService userTagsService;

    @Resource
    private TagLibraryConverter tagLibraryConverter;

    @ApiOperation("后端管理:标签信息新增")
    @PostMapping("/admin/basic/tagLibrary/info/save")
    public Result<Void> save(@RequestBody TagLibraryParam tagLibraryParam) throws BusinessException {
        tagLibraryService.save(tagLibraryParam);
        return Result.success();
    }

    @ApiOperation("后端管理:根据id删除")
    @DeleteMapping("/admin/basic/tagLibrary/info/delete/{id}")
    public Result<Void> delete(@PathVariable("id") Integer id) {
        tagLibraryService.delete(id);
        return Result.success();
    }

    @ApiOperation("后端管理:标签基本信息详情")
    @GetMapping("/admin/basic/tagLibrary/info/detail/{id}")
    public Result<TagLibraryVO> detail(@PathVariable("id") Integer id) {
         TagLibraryBO detail = tagLibraryService.detail(id);
        return new Result<>(tagLibraryConverter.bo2vo(detail));
    }

    @ApiOperation("后端管理:标签基本信息更新")
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "tagLibraryParam", value = "TagLibraryParam",
                            required = false, dataType = "TagLibraryParam")
            })
    @PutMapping("/admin/basic/tagLibrary/info/update/{id}")
    public Result<Void> update(@PathVariable("id") Integer id, @RequestBody TagLibraryParam tagLibraryParam) throws BusinessException {
        tagLibraryService.update(id, tagLibraryParam);
        return Result.success();
    }

    @ApiOperation("后端管理:标签数据基本信息分页查询")
    @GetMapping("/admin/basic/tagLibrary/info/list")
    public Result<PageResult<TagLibraryVO>> list(TagLibraryQuery tagLibraryQuery) {
        PageResult<TagLibraryVO> tagLibraryVOPaginationResult = tagLibraryService.list(tagLibraryQuery);
        return new Result<>(tagLibraryVOPaginationResult);
    }

    @ApiOperation("后端管理:内容标签数据一级下拉list")
    @GetMapping("/admin/basic/tagLibrary/info/articleList")
    public Result<List<TagLibraryVO>> articleTagLibraryList() throws BusinessException {
        List<TagLibraryBO> list = tagLibraryService.articleList();
        List<TagLibraryVO> tagLibraryVOS = tagLibraryConverter.boList2voList1(list);
        return new Result<>(tagLibraryVOS);
    }

    @ApiOperation("前台管理:内容标签数据一级下拉list")
    @GetMapping("/basic/tagLibrary/info/articleList")
    public Result<List<TagLibraryVO>> articleTagLibraryListApp() throws BusinessException {
        List<TagLibraryBO> list = tagLibraryService.articleList();
        List<TagLibraryVO> tagLibraryVOS = tagLibraryConverter.boList2voList1(list);
        return new Result<>(null);
    }

    @ApiOperation("前台管理:内容标签数据二级下拉list")
    @GetMapping("/basic/tagLibrary/info/articleAllList")
    public Result<Map<String, List<UserItemTag>>> articleAllList() throws BusinessException {
        return new Result<>(tagLibraryService.articleAllList());
    }

    @ApiOperation("后端管理:用户标签数据二级菜单list")
    @GetMapping("/admin/basic/tagLibrary/info/userList")
    public Result<Map<String, List<UserItemTag>>> userTagLibraryList() throws BusinessException {
        Map<String, List<UserItemTag>> list = tagLibraryService.userList();
        return new Result<>(list);
    }

    @ApiOperation("前台管理:用户标签数据二级菜单list")
    @GetMapping("/basic/tagLibrary/info/userList")
    public Result<Map<String, List<UserItemTag>>> userTagLibraryListAPP() throws BusinessException {
        Map<String, List<UserItemTag>> list = tagLibraryService.userList();
        return new Result<>(list);
    }

    @ApiOperation("前台管理:用户选择标签")
    @GetMapping("/basic/user/tag")
    public Result<Void> userTag(UserTagsParam param) {
        userTagsService.insert(param);
        return Result.success();
    }

}
